package com.array;

import lombok.Data;

import java.util.Objects;

/**
 * @Author: tgy
 * @Date: 2020-08-26 11:49
 */
@Data
public class Person {

    private String name;

    private Integer age;

    public Person() {

    }

    public Person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {

        if (this == o) {
            return true;
        }
        if (!(o instanceof Person)) {
            return false;
        }
        Person person = (Person) o;
        return getName().equals(person.getName()) &&
                getAge().equals(person.getAge());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getName(), getAge());
    }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();

        System.out.println("销毁 " + this);
    }
}
